package com.liuheqiao.sushegaunli.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.liuheqiao.sushegaunli.R;
import java.util.List;

public class NoticeImageAdapter extends RecyclerView.Adapter<NoticeImageAdapter.ImageViewHolder> {
    private Context context;
    private List<String> images;

    public NoticeImageAdapter(Context context, List<String> images) {
        this.context = context;
        this.images = images;
    }

    @NonNull
    @Override
    public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_notice_image, parent, false);
        return new ImageViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
        String imagePath = images.get(position);
        int resourceId = context.getResources().getIdentifier(
                imagePath.replace("drawable/", ""),
                "drawable",
                context.getPackageName()
        );
        holder.ivNotice.setImageResource(resourceId);
    }

    @Override
    public int getItemCount() {
        return images != null ? images.size() : 0;
    }

    static class ImageViewHolder extends RecyclerView.ViewHolder {
        ImageView ivNotice;

        public ImageViewHolder(@NonNull View itemView) {
            super(itemView);
            ivNotice = itemView.findViewById(R.id.iv_notice);
        }
    }
} 